using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Lesson4 : MonoBehaviour
{
    public Transform Player;
    public Transform target;
    public Button btnLerp;
    public Button btnSlerp;
    public float slerpTime;
    public bool isLerp = true;
    void Start()
    {
        btnLerp.onClick.AddListener(() =>
        {
            isLerp = true;
            Player.position = Vector3.zero;
        });
        btnSlerp.onClick.AddListener(() =>
        {
            slerpTime = 0;
            isLerp = false;
            Player.position = Vector3.zero;
        });
    }

    void Update()
    {
        //线性插值
        if (isLerp)
        {
            Player.position = Vector3.Lerp(Player.position, target.position, Time.deltaTime);
        }
        //球形插值
        else
        {
            slerpTime += Time.deltaTime;
            Player.position = Vector3.Slerp(Vector3.left * 10 + Vector3.up * 0.1f, target.position, slerpTime * 0.5f);
        }
    }
}
